
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region SubjectCategory Model -(by fangyifeng at 2006-10-30 11:49:38)

	/// <summary>
	/// SubjectCategory object'SubjectCategory'.
	/// </summary>
	[Serializable]
	public class SubjectCategory : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _name;
		protected string _discprition;
		protected string _imageUrl;
		protected Subject _subject;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public SubjectCategory() { }

		public SubjectCategory( string name, string discprition, string imageUrl, Subject subject )
		{
			this._name = name;
			this._discprition = discprition;
			this._imageUrl = imageUrl;
			this._subject = subject;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string Name
		{
			get { return _name; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
				_name = value;
			}
		}

		public virtual string Discprition
		{
			get { return _discprition; }
			set
			{
				if ( value != null && value.Length > 200)
					throw new ArgumentOutOfRangeException("Invalid value for Discprition", value, value.ToString());
				_discprition = value;
			}
		}

		public virtual string ImageUrl
		{
			get { return _imageUrl; }
			set
			{
				if ( value != null && value.Length > 200)
					throw new ArgumentOutOfRangeException("Invalid value for ImageUrl", value, value.ToString());
				_imageUrl = value;
			}
		}

		public virtual Subject Subject
		{
			get { return _subject; }
			set { _subject = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is SubjectCategory))
				throw new InvalidCastException("This object is not of type SubjectCategory");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((SubjectCategory)obj).Id);
					break;
				case "Name":
					relativeValue = this.Name.CompareTo(((SubjectCategory)obj).Name);
					break;
				case "Discprition":
					relativeValue = (this.Discprition != null) ? this.Discprition.CompareTo(((SubjectCategory)obj).Discprition) : -1;
					break;
				case "ImageUrl":
					relativeValue = (this.ImageUrl != null) ? this.ImageUrl.CompareTo(((SubjectCategory)obj).ImageUrl) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (SubjectCategory.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
